package org.cash.strategy;

import org.cash.cashrule.CashDiscount;
import org.cash.cashrule.CashNormal;
import org.cash.cashrule.CashReturn;
import org.cash.cashrule.CashSuper;

import java.math.BigDecimal;

public class CashContext {
    private CashSuper cs;

    public CashContext(String ruleType) {
        switch (ruleType) {
            case "NORMAL"://正常销售价
                this.cs = new CashNormal();
                break;
            case "DISCOUNT"://打折价
                this.cs = new CashDiscount(0.8d);
                break;
            case "RETURN"://满减价
                this.cs = new CashReturn(100d, 10d);
                break;
            default:
                throw new IllegalArgumentException("参数错误");
        }
    }

    public BigDecimal getCash(BigDecimal money) {
        return this.cs.acceptCash(money);
    }
}
